package top.rainbowecho.article.advice;

import com.google.common.collect.ImmutableMap;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import top.rainbowecho.common.exception.BlogException;
import top.rainbowecho.common.util.ResultKey;

import java.util.Map;

/**
 * @author rainbow
 * @since 2020/7/27 17:23
 */
@RestControllerAdvice
public class ApplicationHandler {
    @ExceptionHandler(BlogException.class)
    public ResponseEntity<Map<String, Object>> handleBlogException(Throwable tx) {
        Map<String, Object> result = ImmutableMap.of(ResultKey.EXCEPTION_MESS.trim(), tx.getMessage());
        return new ResponseEntity<>(result, HttpStatus.INTERNAL_SERVER_ERROR);
    }
}
